<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>03_原型链_属性问题</title>
</head>
<body>
<!--
1、读取对象的属性时：会自动到原型链中查找
2、设置对象的属性时：不会查找原型链，如果当前对象中没有该属性，直接添加此属性并设置值
3、方法一般定义在原型中，熟悉一般通过构造函数定义在对象本身上
-->
<script>
function Fn() {

}

Fn.prototype.a = 'xxx'

var fn1 = new Fn();
console.log(fn1.a, fn1)
var fn2 = new Fn();
fn2.a = 'yyy';
console.log(fn1.a, fn2.a, fn2)

function Person(name, age) {
    this.name = name
    this.age = age
}

Person.prototype.setName = function (name) {
    this.name = name
}
var p1 = new Person("Jack", 18)
p1.setName('Cat')
console.log(p1)
</script>
</body>
</html>